package ynu.lcy.entity;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;
import org.hibernate.annotations.Where;
import ynu.lcy.elememicroservicecommon.entity.LogicEntity;

import javax.persistence.*;
import java.util.List;

/**
 * 购物车实体
 * */
@Entity
@Setter
@Getter
@NoArgsConstructor
@Where(clause = "is_deleted = 0")
@JsonIgnoreProperties(value = {"hibernateLazyInitializer", "handler", "fieldHandler"})
public class Cart extends LogicEntity {
    /**
     * 所属商家
     * */
    private Long businessId;
    /*
    * 所属用户
    * */
    private Long userId;
    /*
    * 数量
    * */
    private Integer totalQuantity;
    /**
     * 购物车内容
     * */
    @OneToMany(mappedBy = "cart",
            fetch = FetchType.EAGER,
            orphanRemoval = true,
            cascade = CascadeType.ALL)
    @JsonIgnoreProperties(value = {"cart"})
    @Fetch(FetchMode.SUBSELECT)
    private List<CartFoodItem> cartItems;
}
